package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsOrderGoodsMapper;
import com.qf.mapper.DtsOrderMapper;
import com.qf.mapper.DtsUserMapper;
import com.qf.mapper.StatMapper;
import com.qf.pojo.DtsOrder;
import com.qf.pojo.DtsOrderGoods;
import com.qf.pojo.DtsUser;
import com.qf.service.DtsOrderService;
import com.qf.vo.DayStatis;
import com.qf.vo.ShipChannelListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author Cc
 * @version 1.0
 */
@Service
public class DtsOrderServiceImpl implements DtsOrderService {

    @Autowired
    private DtsOrderMapper dtsOrderMapper;

    @Autowired
    private DtsOrderGoodsMapper dtsOrderGoodsMapper;

    @Autowired
    private StatMapper statMapper;
    @Autowired
    private DtsUserMapper userMapper;

    @Override
    public int count() {
        QueryWrapper<DtsOrder> wrapper = new QueryWrapper<>();
        wrapper.eq("deleted", false);
        Integer count = dtsOrderMapper.selectCount(wrapper);
        return count;
    }

    @Override
    public List<DayStatis> findDayStatis() {
        return dtsOrderMapper.findDayStatis();
    }

    @Override
    public List<DayStatis> recentCount(int statisDaysRang) {
        return statMapper.orderDayStatistic(statisDaysRang);
    }

    @Override
    public IPage<DtsOrder> page(Integer page, Integer limit, String sort, String order) {
        return dtsOrderMapper.selectPage(new Page<>(page, limit),
                new QueryWrapper<DtsOrder>()
                        .eq("deleted", false)
                        .orderBy(!StringUtils.isEmpty(sort), "ASC".equalsIgnoreCase(order), sort));
    }

    @Override
    public List<ShipChannelListVo> listShipChannel() {
        return dtsOrderMapper.listShipChannel();
    }


    @Override
    public DtsOrder orderById(Integer id) {
        return dtsOrderMapper.selectById(id);
    }

    @Override
    public DtsUser userByid(Integer userId) {
        return userMapper.selectById(userId);
    }

    @Override
    public List<DtsOrderGoods> goosById(Integer id) {
        return dtsOrderGoodsMapper.selectList(new QueryWrapper<DtsOrderGoods>()
                .eq("order_id",id));
    }


}
